//
//  FCVehicleStatusController.m
//  OilWear
//
//  Created by jjkj on 17/7/10.
//  Copyright © 2017年 jjkj. All rights reserved.
//
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
#define kAlarmViewHeight ((CGFloat)80/375) * kScreenWidth

#import "FCVehicleStatusController.h"
#import "FCSwitchView.h"
#import "FCAlamView.h"
#import "FCMileageAndOilWearView.h"
#import "CLWorkAreaDetailViewController.h"
#import "HomeCarModel.h"
#import "FCVehicleReamTimeStatusController.h"//车辆实时状态
#import "CustomChooseBoxView.h"
#import "YHIolInfoListView.h"
@interface FCVehicleStatusController ()

@property (nonatomic,strong) NSMutableDictionary *homeCarParamsDic;//请求参数

@property (nonatomic,strong) HomeCarModel *homeCarModel;//车辆首页model

@property (nonatomic,strong) CustomChooseBoxView *chooseBoxView;

@property (nonatomic,strong) FCAlamView *alarmView ;

/**报警列表*/
@property (nonatomic,strong) YHIolInfoListView * iolInfoListView;

@end

@implementation FCVehicleStatusController

-(YHIolInfoListView *)iolInfoListView
{
    if (!_iolInfoListView) {
        _iolInfoListView = [YHIolInfoListView viewFromXib];
        _iolInfoListView.frame = CGRectMake(5, self.view.height - 50, kScreenWidth-10, 0);
        [self.view addSubview:_iolInfoListView];
    }
    return _iolInfoListView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.switchView setUpSwitchButtonAppreace:1];
    [self setUpChooseWorkAreaBoxView];
    
    [self setUpAlarmView];
    [self setUpVehicleAmountAndMileageView];

    self.homeCarParamsDic = [NSMutableDictionary dictionaryWithDictionary:@{
                                                                            @"starttime":@"2017-07-11",
                                                                            @"endtime":@"2017-07-11",
                                                                            
                                            @"workShopId":@"a892c48707064e189b2173c703420364",
                                                                            
                                                                    }];
    [self getHomeCarInfoListWith:self.homeCarParamsDic];
    // Do any additional setup after loading the view.
}

- (void)setUpAlarmView {
    
    self.alarmView = [[NSBundle mainBundle] loadNibNamed:@"FCAlamView" owner:self options:nil].firstObject;
    [self.view addSubview:self.alarmView];
    
    self.alarmView.frame = CGRectMake(0, kScreenHeight - kAlarmViewHeight,kScreenWidth,kAlarmViewHeight);
    
    __weak typeof(self) weakSelf = self;
    
    //切换报警弹框内容事假处理
    self.alarmView.exchangeAlarmBlock = ^(NSInteger tag){
        [weakSelf changeAlarmTypeWithTag:tag];
    };

}
//切换报警弹框内容
- (void)changeAlarmTypeWithTag:(NSInteger )tag {
    
    NSInteger index = tag - 200;
   
    switch (index) {
        case 0:
            self.iolInfoListView.type = 0;
            break;
        case 1:
             NSLog(@"弹出故障报警");
            break;
        case 2:
             NSLog(@"弹出超速报警");
            break;
        case 3:
             NSLog(@"弹出加油报警");
            break;
            
        default:
            break;
    }
    self.iolInfoListView.isCar = YES;
    if (index == globalNum0) {
        self.iolInfoListView.type = index;
    }else{
        self.iolInfoListView.type = index+1;
    }
    self.iolInfoListView.startTime = @"2017-01-01";
    self.iolInfoListView.endTime = @"2017-07-13";
    self.iolInfoListView.carShopId = @"a892c48707064e189b2173c703420364";
    if ([self.iolInfoListView isShow]) {
        [self.iolInfoListView hidden];
    }else{
        [self.iolInfoListView show];
    }
}

- (void)setUpVehicleAmountAndMileageView {
    
    FCMileageAndOilWearView *mileageAndOilWearView = [[NSBundle mainBundle] loadNibNamed:@"FCMileageAndOilWearView" owner:self options:nil].firstObject;
    [self.view addSubview:mileageAndOilWearView];
    
    mileageAndOilWearView.frame = CGRectMake(0, CGRectGetMaxY(self.chooseBoxView.frame), kScreenWidth,kScreenHeight - CGRectGetMaxY(self.chooseBoxView.frame) - CGRectGetHeight(self.alarmView.frame));
    
    __weak typeof(self) weakSelf = self;
    
    mileageAndOilWearView.workAreaDetailBlock = ^(){
        
        CLWorkAreaDetailViewController *workAreaDetailVC = [[CLWorkAreaDetailViewController alloc] init];
        [weakSelf.navigationController pushViewController:workAreaDetailVC animated:YES];
    };

    mileageAndOilWearView.exchangeVehicleBlock = ^(NSInteger index){
        //进入车辆实时状态页面
//        FCVehicleReamTimeStatusController *vehicleReamTimeStatusVC = [[FCVehicleReamTimeStatusController alloc] init];
//        [weakSelf.navigationController pushViewController:vehicleReamTimeStatusVC animated:YES];
        [weakSelf changeAlarmTypeWithTag:203];
    };
}

- (void)setUpChooseWorkAreaBoxView {
    
    self.chooseBoxView = [[NSBundle mainBundle] loadNibNamed:@"CustomChooseBoxView" owner:self options:nil].firstObject;
    [self.view addSubview:self.chooseBoxView];
    
    self.chooseBoxView.frame = CGRectMake(15, CGRectGetMaxY(self.switchView.frame) + 15, kScreenWidth - 30, 45);
    self.chooseBoxView.dataArray = [NSMutableArray arrayWithArray:@[@"其他",@"外部单位",@"铁运车间",@"汽运作业区",@"兴茂公司"]];
    //选择工作区操作
    self.chooseBoxView.chooseBoxClickBlock = ^(NSString *chooseResult){
    
    
    };
    //[self.chooseBoxView changeChooseBoxTitle:@"铁运车间"];
//    [chooseBoxView.chooseButton setImageEdgeInsets:UIEdgeInsetsMake(0,chooseBoxView.chooseButton.titleLabel.bounds.size.width, 0, -chooseBoxView.chooseButton.titleLabel.bounds.size.width)];
//    [chooseBoxView.chooseButton setTitleEdgeInsets:UIEdgeInsetsMake(0,-20, 0, 20)];

}

#pragma mark - 网络请求

- (void)getHomeCarInfoListWith:(NSMutableDictionary *)dic {
    
    [HomeCarModel getHomeCarInfoList:dic success:^(NSDictionary *response) {
        NSLog(@"getHomeCarInfoList_____%@response",response);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
